package net.xo68.destiny.contract.domain.node;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import net.xo68.destiny.contract.enums.NodeTypeEnum;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * 节点注册模型
 * @author wuxie
 * @version 2020-10-25
 */
@ApiModel("节点注册模型")
@ToString
@Data
public class NodeRegistry implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * 节点类型
     */
    @ApiModelProperty("节点类型")
    private NodeTypeEnum nodeType;
    /**
     * 工作组英文名称
     */
    @ApiModelProperty("工作组英文名称")
    private String workGroup;
    @ApiModelProperty("节点地址，格式：ip:port")
    private String nodeHost;
    @ApiModelProperty("cpu使用情况")
    private double cpuUsage;
    @ApiModelProperty("内存使用情况")
    private double memoryUsage;
    @ApiModelProperty("cpu负荷")
    private double loadAverage;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @ApiModelProperty("最后注册时间")
    private Date lastTime;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        NodeRegistry that = (NodeRegistry) o;
        return nodeHost.equals(that.nodeHost);
    }

    @Override
    public int hashCode() {
        return Objects.hash(nodeHost);
    }
}
